package com.bqtt.tumor.demo.business;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bqtt.tumor.demo.common.MyBeanFactory;
import com.bqtt.tumor.demo.data_access.HealthUserDAO;
import com.bqtt.tumor.demo.data_access.MedicalCaseDAO;
import com.bqtt.tumor.demo.entity.HealthUser;
import com.bqtt.tumor.demo.entity.MedicalCase;

public class MedicalCaseService {

	private static Logger log = LoggerFactory.getLogger(MedicalCaseService.class);
	
	private static MedicalCaseDAO medicalCaseDAO = (MedicalCaseDAO) MyBeanFactory.getBean("medicalCaseDAO");
	
	
	public static List<MedicalCase> searchByCondition(MedicalCase condition,int pageSize,int pageNo)
	{
		
		List<MedicalCase> result = medicalCaseDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);
		
		for(MedicalCase item:result)
		{
			item.fillStringField();
		}
		return result;
	}
	
	
	
	public static List<MedicalCase> searchByCondition(MedicalCase condition,int pageSize,int pageNo,long id)
	{
		
		List<MedicalCase> result = medicalCaseDAO.fuzzyFindByProperties(condition.getSQLValidAttributes(),pageSize,pageNo);
		
		for(MedicalCase item:result)
		{
			if(item.getMedical_case_id()==id)
			{
				item.setDisplayName("inline-block");
			}
			item.fillStringField();
		}
		return result;
	}
	
	public static MedicalCase findById(Integer id)
	{
		return medicalCaseDAO.findById(id);
	}
	
	public static boolean add(MedicalCase medicalCase)
	{
		try
		{
			medicalCase.fillDBfields();
			medicalCaseDAO.save(medicalCase);
			return true;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
		
	}
	
	public static boolean update(MedicalCase medicalCase)
	{
		try
		{
			medicalCase.fillDBfields();
			if(medicalCase.getMedical_case_id()>0)
			{
				medicalCaseDAO.update(medicalCase);
				return true;
			}
			else
				
			return false;
		}
		catch(Exception e)
		{
			log.error(e.getMessage());
	     	return false;	
		}
	}
}
